#pragma once

namespace galois
{
namespace cont
{

class ArrayHandleBase
{
};

template <typename T>
class ArrayHandle : public ArrayHandleBase
{
public:
  void Allocate(size_t size)
  {
    this->_size = size;
    this->_data = new T[size];
  }

  ArrayHandle()
    : _size(0)
    , _data(nullptr){};

  ArrayHandle(const ArrayHandle& other)
    : _size(other._size)
  {
    delete _data;
    _data = new T[_size];
    for (size_t i = 0; i < _size; i++)
    {
      *this[i] = other[i];
    }
  }

  ArrayHandle(ArrayHandle&& other) noexcept
    : _size(std::move(other._size))
    , _data(other._data)
  {
    other._data = nullptr;
    other._size = 0;
  }

  T& operator[](size_t i) const { return _data[i]; }
  virtual ~ArrayHandle() { delete _data; }

  size_t Length() const { return _size; }

private:
  size_t _size;
  T* _data;
};

}
}
